import os
import re

from Netease_album_info import *
from Netease_song_info import *
from Netease_translated_lyrics import *


def save_info(song_info, song_id, album_info_dict):
    print('保存信息中——————————————————')

    song_url = f'https://music.163.com/#/song?id={song_id}'
    new_song_url = song_url.replace(' ', '')

    if not os.path.exists(f'./{song_info}'):
        os.mkdir(f'./{song_info}')

    with open(f'./{song_info}/{song_info}.txt', 'w', encoding='utf8') as fp:
        info = f'''【】{song_info}\n\
\n\
{album_info_dict["publish_time"]}\n\
{album_info_dict["publisher"]}\n\
网易云链接:{new_song_url}\
\n\
\nB站：'''

        fp.write(info)
    print(song_info + '.txt 保存完成！——————————————————')

def run():
    global song_id

    get_song_info = song()
    song_info = get_song_info.run(song_id)
    

    lyric = translated_lyrics()
    lyric.run_lyric(song_id, song_info)
    

    album = album_info()
    album_info_dict = album.run_album(song_id)
    print(album_info_dict)
    save_info(song_info, song_id, album_info_dict)

    print('结束！——————————————————')

if __name__ == '__main__':
    wyy_id = input('歌曲id或网址：\n')  # 1398628590  148261480
    try:
        song_id = re.findall(f'(\d+)', wyy_id)[1]
    except:
        song_id = re.findall(f'(\d+)', wyy_id)[0]

    '''  #下面的可以变成上面的 

        flag = int(input('1.歌曲id  2.网易云网址\n'))
        wyy_id = input('网易云id：\n')  # 1398628590  148261480
        if flag == 1:
            song_id = wyy_id
        elif flag == 2:
            song_id = re.findall(f'(\d+)', wyy_id)[1]
        else:
            print('输入有误')
    ''' 

    #print(song_id)
    
    run()
